#include <iostream>
#include <cstring>

//基于规则，编译器给你写代码
//模板只有在调用时，才会创建相应类型的函数
template<typename T>
void Print(T value)
{
    std::cout << value << std::endl;
}

//模板传类型和整数
template<typename T, int N>
class Array{
public:
    T GetSize() const 
    {
        return N;
    }

    constexpr T Size() const //编译器确定
    {
        return N;
    }

    T& operator[](size_t index)
    {
        return m_Array[index];
    }

    const T& operator[](size_t index) const
    {
        return m_Array[index];
    }

    T* Data(){
        return m_Array;
    }

    const T* Data() const 
    {
        return m_Array;
    }

private:
     T m_Array[N];
};

int main()
{
    Print<int>(5); 
    Print<std::string>("cc");

    Array<int, 7> array;
    memset(&array[0], 0 , array.Size() * sizeof(int));
    array[0] = 11;
    array[1] = 22;
    array[5] = 55;

    static_assert(array.Size() < 10, "Size is to large!");
    std::cout << array.GetSize() << std::endl; // 7

    const auto& arrayReference = array;
    for(size_t i = 0; i < array.Size(); i++)
    {
       array[i] = 2;
       std::cout << arrayReference[i] << std::endl;

    }
    Array<std::string, 6> array2;

}
